import React from "react";
import { useRoutes } from "./hooks";

export default function Routes({ children }) {
  // 1. 将子组件遍历成routes（路由配置）
  const routes = [];

  React.Children.forEach(children, (element) => {
    // forEach(需要遍历的数组，遍历触发的函数)
    // console.log(element);
    routes.push({
      path: element.props.path,
      element: element.props.element,
    });
  });

  // 2. 使用useRoutes(routes)来渲染路由
  return useRoutes(routes);
}
